package com.zx.sys.user.oauth2;


import com.zx.sys.user.entity.SysUserEntity;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Shiro工具类
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年11月12日 上午9:49:19
 */
public class ShiroUtils {

	private Logger logger = LoggerFactory.getLogger(ShiroUtils.class);
	/**
	 * 站点KEY
	 */
	public static final String SITE_OBJECT = "_site_object";

	/**
	 *  session  可以会全部取消，因为当做tomcat 集群时session会出问题。
	 * @return
	 */
	public static Session getSession() {
		return SecurityUtils.getSubject().getSession();
	}

	public static Subject getSubject() {
		return SecurityUtils.getSubject();
	}

	public static SysUserEntity getUserEntity() {
		return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
	}

	public static Long getUserId() {
		return getUserEntity().getUserId();
	}


	public static boolean isLogin() {
		return SecurityUtils.getSubject().getPrincipal() != null;
	}



}
